<template>
  <el-row>
    <el-col :span="24">
      <el-card>
        <el-form :inline="true" class="demo-form-inline">
          <!-- <el-form-item>
            <el-button type="success" style="margin-bottom: 10px;" @click="ShowAddDialog">添加</el-button>
          </el-form-item> -->
          <el-form-item>
            <div style="margin-top: 20px" @change="selectOstate(1)">
              <el-radio-group v-model="ostate">
                <el-radio value="1" border>进行中</el-radio>
                <el-radio value="2" border>已过期</el-radio>
                <el-radio value="3" border>已完成</el-radio>
                <el-radio value="" border>所有订单</el-radio>
              </el-radio-group>
            </div>
          </el-form-item>
        </el-form>
        <el-table :data="pageInfo.list" border style="width: 100%">
          <el-table-column prop="oid" label="ID" />
          <el-table-column prop="admin.name" label="用户名" />
          <el-table-column prop="cars.eavatar" label="头像">
            <template #default="scope">
              <el-avatar shape="square" :size="50" :src="'http://localhost:8080/upload/' + scope.row.cars.eavatar" />
            </template>
          </el-table-column>
          <el-table-column prop="cars.cplate" label="车牌号" />
          <el-table-column prop="cars.brand" label="品牌" />
          <el-table-column prop="orderstime" label="下单时间" />
          <el-table-column prop="days" label="租赁天数" />
          <el-table-column prop="pay" label="总价格"></el-table-column>
          <el-table-column prop="admin.telephone" label="用户电话" />
          <el-table-column prop="ostate" label="订单状态">
            <template #default="scope">
              <span v-if="scope.row.ostate == 1">
                <el-tag type="primary">进行中</el-tag></span>
              <span v-else-if="scope.row.ostate == 2"> <el-tag type="info">已过期</el-tag></span>
              <span v-else-if="scope.row.ostate == 3"> <el-tag type="erorr">已完成</el-tag></span>
            </template>
          </el-table-column>
        </el-table>
        <el-row class="row-bg" justify="center" style="margin-top: 20px;">
          <el-pagination background layout="prev, pager, next" v-model:current-page="pageInfo.pageNum"
            v-model:page-count="pageInfo.pages" @updare:current-page="selectOstate" />
        </el-row>

      </el-card>
    </el-col>
  </el-row>
</template>


<script setup>
import { ElMessage } from 'element-plus';
import { computed, reactive, ref } from 'vue';
import { ElLoading } from 'element-plus'
import ordersApi from '@/api/ordersApi';
import carsApi from '@/api/carsApi';
const headers = computed(() => {
  let token = sessionStorage.getItem("token");
  return {
    token
  }


});

//修改框
const ordersUpdateDialogShow = ref(false);
//所有车辆的
const carsList = ref([]);
//用来搜索的关键字
const ostate = ref('');
const pageInfo = ref({
  total: 0,
  pageSize: 0,
  pageNum: 0
});
//上传图片的地址
const imageUrl = ref("");



//定义方法根据cid查询车辆信息
function selectByOid(oid) {
  carsApi.selectByCplate("")
    .then(resp => {
      carsList.value = resp.data;
    });
  ordersApi.selectByOid(oid)
    .then(resp => {
      carsUpdate.value = resp.data;
      //显示修改框
      ordersUpdateDialogShow.value = true;
    });
}
//分页查询；  
function selectOstate(pageNum) {
  ordersApi.selectOstate(pageNum, ostate.value)
    .then(resp => {
      pageInfo.value = resp.data;
    });
}
//默认查询首页
selectOstate(1);
</script>

<style scoped></style>